package com.framework.plm.bas.util;

import net.sf.cglib.beans.BeanCopier;

import com.framework.plm.bas.exception.PlmBasException;

@SuppressWarnings("unchecked")
public class UtilBean {
	
	/**
	 * 复制对象信息
	 * @param source 源对象
	 * @param dest 目标对象
	 * @return
	 */
	public static void copyObject(Object source, Object dest){
		BeanCopier copy = null;
		if (source!=null && dest!=null){
			copy = BeanCopier.create(source.getClass(), dest.getClass(), false);
			copy.copy(source, dest, null);
		}
	}
	
	/**
	 * 复制对象信息
	 * @param source 源对象
	 * @param Class 目标对象类
	 * @return Object 目标对象类的实例
	 */
	public static Object copyObject(Object source, Class claz){
		BeanCopier copy = null;
		Object obj = null;
		if (source!=null){
			copy = BeanCopier.create(source.getClass(), claz, false);
			try{
				obj = claz.newInstance();
			}catch(Exception e){
				throw new PlmBasException(e.getMessage(), e);
			}
			copy.copy(source, obj, null);
		}
		return obj;
	}

}
